package com.csjy.migration.hnnd.workflow;

import com.csjy.migration.hnnd.BusinessTool;
import com.csjy.migration.hnnd.DbUtil;
import com.csjy.migration.hnnd.ProgramArgument;
import com.csjy.migration.hnnd.annotation.Task;
import com.csjy.migration.hnnd.business.NdBpmFeeCollectionRecord;
import com.csjy.migration.hnnd.business.NdBpmResponCompensatory;
import com.csjy.migration.hnnd.business.SourceBusinessData;

import java.sql.SQLException;
import java.util.Map;

/**
 * 委托代偿审批
 */
public class ItemSencorLoanWeiHny extends WorkflowMigration {
    private NdBpmFeeCollectionRecord ndBpmFeeCollectionRecord = null;
    private NdBpmResponCompensatory ndBpmResponCompensatory = null;
    public ItemSencorLoanWeiHny(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId, String procInstId, Map procInstRow) throws Exception {
        super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId, procInstId, procInstRow);
        this.customInitData();
    }

    @Override
    public void customInitData() throws SQLException {
        this.ndBpmFeeCollectionRecord = new NdBpmFeeCollectionRecord(sourceDbUtil,targetDbUtil,sourceData,programArgument,projectId,procInstId,true);
        this.ndBpmResponCompensatory = new NdBpmResponCompensatory(sourceDbUtil,targetDbUtil,sourceData,programArgument,projectId,procInstId);
        this.curBizType = "bddc";
    }

    @Override
    public void customInsertOrUpdateData() throws Exception {

    }



    @Task("委托代偿审批@项目经理提交申请")
    public void wtdcspxmjltjsq() throws Exception{
        this.curAffixTypeCommon = "yhtz";
        this.curAffixType = "qtfj";
        //
        String sencorType = this.getJbpmVarInstValueByName("checkOnlyPromCont");
        if(sencorType.equals("0")) {
            this.curCustomData.put("applicationApprovalType","1");
        } else if(sencorType.equals("1")) {
            this.curCustomData.put("applicationApprovalType","2");
        } else if(sencorType.equals("2")) {
            this.curCustomData.put("applicationApprovalType","3");
        }
        //授信开始日期
        this.curCustomData.put("creditTimeStart",this.getJbpmVarInstValueByName("auditTime"));
        //授信到期日期
        this.curCustomData.put("creditTimeEnd",this.getJbpmVarInstValueByName("assumpTime"));
        // 项目授信总额
        this.curCustomData.put("creditMoney",this.getJbpmVarInstValueByName("transacAssureSum"));
        // 已占用放款额
        this.curCustomData.put("coverageMoney",this.getJbpmVarInstValueByName("totalOutAskSum"));
        // 可用申请余额
        this.curCustomData.put("repalyMoney",this.getJbpmVarInstValueByName("allCanUseSum"));
        //担保协议编号
        this.curCustomData.put("guarantAgreeNo",this.getJbpmVarInstValueByName("assuContractNo"));
        //担保协议开始时间
        this.curCustomData.put("agreeTimeStart",this.getJbpmVarInstValueByName("assuContractBtime"));
        //担保协议到期日期
        this.curCustomData.put("agreeTimeEnd",this.getJbpmVarInstValueByName("assuContractEtime"));
        //出保银行名称
        this.curCustomData.put("pro_class",this.getJbpmVarInstValueByName("promBank"));

        //银行支行名称
        this.curCustomData.put("probankName",this.getJbpmVarInstValueByName("bankBranchName"));
        //原已出保金额
        this.curCustomData.put("repayVoucher",this.getJbpmVarInstValueByName("totalOutPromSum"));
        //项目原在保额
        this.curCustomData.put("reCoverageMoney",this.getJbpmVarInstValueByName("askDeferSum"));
        //按年支付担保费  assFareWay.style.display = "";span_assFareWay.innerText = "按年收取担保费";
        this.curCustomData.put("payAnnually",this.getJbpmVarInstValueByName("assFareWay"));
        //本次出保金额
        this.curCustomData.put("repayVoucher2",this.getJbpmVarInstValueByName("promSum"));
        //TODO 担保项目品种
        this.curCustomData.put("proClass",this.getJbpmVarInstValueByName("assureClass"));
        //用款开始时间
        this.curCustomData.put("shouldRepaymentDate",this.getJbpmVarInstValueByName("promContBtime"));
        //用款到期时间
        this.curCustomData.put("shouldRepaymentDateEnd",this.getJbpmVarInstValueByName("promContEtime"));
        //用款协议编号
        this.curCustomData.put("creditFile",this.getJbpmVarInstValueByName("loanContractNo"));
        //客户还款方式
        this.curCustomData.put("repay_type",this.getJbpmVarInstValueByName("returnWay"));
        //月利率
        this.curCustomData.put("repaymentInterestRate",this.getJbpmVarInstValueByName("yearRate"));
        //本次申请放款
        this.curCustomData.put("payMoney",this.getJbpmVarInstValueByName("thisAskUseSum"));
        this.curCustomData.put("virtualPayMoney",this.getJbpmVarInstValueByName("thisAskUseSum"));
        //本次放款支行名称
        this.curCustomData.put("planRepay",this.getJbpmVarInstValueByName("clientBranchName"));
        this.curCustomData.put("bankName",this.getJbpmVarInstValueByName("clientBranchName"));
        //放款银行名称
        this.curCustomData.put("copanyDepart",this.getJbpmVarInstValueByName("clientBankId"));
        this.curCustomData.put("bank",this.getJbpmVarInstValueByName("clientBankId"));

        //本次放款银行账号
        this.curCustomData.put("payAccountNo",this.getJbpmVarInstValueByName("clientBankAccount"));


        this.curModelMap.put("all", new String[]{"task1601198815913xyb","下一步"});
        this.setCommonData(true, null);
        this.ndBpmFeeCollectionRecord.getTaskParamMap().put(curJbpmTaskInstanceId,this.initTaskParamMap());
        this.ndBpmResponCompensatory.getTaskParamMap().put(curJbpmTaskInstanceId,this.initTaskParamMap());
    }

    @Task("委托代偿审批@BC经理审核")
    public void wtdcspbcjlsh()throws Exception{
        this.curAffixTypeCommon = "yhtz";
        this.curAffixType = "qtfj";
        this.curModelMap.put("通过", new String[]{"exclusiveGateway1601198881923xyb","下一步"});
        this.curModelMap.put("同意", new String[]{"task1601198818017ty","下一步"});
        this.setCommonData(true, null);

    }

    @Task("委托代偿审批@办事处负责人审批")
    public void wtdcspbscfzrsp()throws Exception{
        this.curAffixTypeCommon = "yhtz";
        this.curModelMap.put("通过", new String[]{"task1601198936919xyb","下一步"});
        this.curModelMap.put("同意", new String[]{"task1601198936919xyb","下一步"});
        this.setCommonData(true, null);
    }

    @Task("委托代偿审批@分公司负责人审批")
    public void wtdcspfgsfzrsp()throws Exception{
        this.curModelMap.put("通过", new String[]{"task1601198936919xyb","下一步"});
        // todo 同意按钮下一个节点不知道会映射到到哪一个节点，暂时也给下一步节点
        this.curModelMap.put("同意", new String[]{"task1601198936919xyb","下一步"});
        this.setCommonData(false, null);
    }

    @Task("委托代偿审批@分管副总审批")
    public void wtdcspfgfzsp()throws Exception{
        this.curModelMap.put("同意", new String[]{"task1601198944762xyb","下一步"});
        // todo
        this.curModelMap.put("不同意", new String[]{"",""});
        this.setCommonData(false, null);
    }

    @Task("委托代偿审批@经办人审核材料")
    public void wtdcspjbrshcl()throws Exception{
        this.curAffixTypeCommon = "yhtz";
        this.curModelMap.put("通过", new String[]{"task1601198955220xyb","下一步"});
        this.setCommonData(false, null);
    }

    @Task("委托代偿审批@委托代偿经办人审批")
    public void wtdcjbrsp()throws Exception{
        this.wtdcspjbrshcl();
    }


    @Task("委托代偿审批@法务部经理审批")
    public void wtdcspfwbjlsp()throws Exception{
        this.curModelMap.put("同意", new String[]{"task1601198958934xyb","下一步"});
        // todo
        this.curModelMap.put("不同意", new String[]{"",""});
        this.setCommonData(false, null);
    }

    @Task("委托代偿审批@总经理审批")
    public void wtdcspzjlsp()throws Exception{
        this.curModelMap.put("同意", new String[]{"task1601198961543xyb","下一步"});
        // todo
        this.curModelMap.put("不同意", new String[]{"",""});
        this.setCommonData(false, null);
    }

    @Task("委托代偿审批@董事长审批")
    public void wtdcspdszsp()throws Exception{
        this.curModelMap.put("同意", new String[]{"task1601198963631xyb","下一步"});
        // todo
        this.curModelMap.put("不同意", new String[]{"",""});
        this.setCommonData(false, null);
    }

    @Task("委托代偿审批@经办人处理放款")
    public void wtdcspjbrblfk()throws Exception{
        this.curAffixType = "yhtz";
        this.curAffixTypeCommon = "qtfj";
        //实际放款金额
        this.curCustomData.put("virtualPayMoney",this.getJbpmVarInstValueByName("sureAskUseSum"));
        //还款年息利率
        this.curCustomData.put("annualInterestRate",this.getJbpmVarInstValueByName("monthRate"));
        //用款开始时间
        this.curCustomData.put("payDate",this.getJbpmVarInstValueByName("accountBtime"));
        //用款到期时间
        this.curCustomData.put("endDate",this.getJbpmVarInstValueByName("promContEtime"));
        //资金来源名称
        this.curCustomData.put("bank",this.getJbpmVarInstValueByName("exPromBank"));
        //放款银行支行名称
        this.curCustomData.put("bankName",this.getJbpmVarInstValueByName("exBankBranchName"));
        this.curModelMap.put("all", new String[]{"endxyb","下一步"});
        this.setCommonData(true, null);
    }
}
